home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / dmake38c.zip / UTIME.C < prev    next >
C/C++ Source or Header  |  1992-01-23  |  808b  |  49 lines

  1. /*
  2. ** change access and modify times of file
  3. */
  4. #include <sys/types.h>
  5. #include <sys/time.h>
  6. #include <sys/stat.h>
  7. #include <sys/file.h>
  8.  
  9. int
  10. utime(name, timep)
  11. char*    name;
  12. time_t    timep[2];
  13. {
  14.     struct timeval tv[2], *tvp;
  15.     struct stat buf;
  16.     int    fil;
  17.     char    data;
  18.  
  19.     if (timep!=0)
  20.     {
  21.         tvp = tv, tv[0].tv_sec = timep[0], tv[1].tv_sec = timep[1];
  22.         if (utimes(name, tvp)==0)
  23.             return (0);
  24.     }
  25.  
  26.     if (stat(name, &buf) != 0)
  27.         return (-1);
  28.     if (buf.st_size != 0)  {
  29.         if ((fil = open(name, O_RDWR, 0666)) < 0)
  30.             return (-1);
  31.         if (read(fil, &data, 1) < 1) {
  32.             close(fil);
  33.             return (-1);
  34.         }
  35.         lseek(fil, 0L, 0);
  36.         if (write(fil, &data, 1) < 1) {
  37.             close(fil);
  38.             return (-1);
  39.         }
  40.         close(fil);
  41.         return (0);
  42.     } else     if ((fil = creat(name, 0666)) < 0) {
  43.         return (-1);
  44.     } else {
  45.         close(fil);
  46.         return (0);
  47.     }
  48. }
  49.